#include "MyArray.h"

MyArray::MyArray(int length){
        if(length < 0){
                m_length = 0;
        }
        m_length = length;
        m_space = new int[m_length];
}

//赋值(拷贝)构造函数
MyArray::MyArray(const MyArray &obj){
        this->m_length = obj.m_length;
        this->m_space = new int[this->m_length];

        for (int i = 0; i < this->m_length; i++) //数组元素复制 
        {
                this->m_space[i] = obj.m_space[i];
        }
        
}

MyArray::~MyArray(){
        if(m_space){
                delete [] m_space;
                m_length = 0;
        }
}

void MyArray::setData(int index, int value){
        m_space[index] = value;
}

int MyArray::getData(int index){
        return m_space[index];
}

int MyArray::length(){
        return m_length;
}